package com.common.www.service.tabulation;


import org.springframework.boot.base.jpa.service.BaseLogicService;
import com.common.www.bean.entity.project.Project;
import com.common.www.bean.entity.project.XfgcBiddingCompany;
import com.common.www.bean.entity.tabulation.XfgcSummary;
import com.common.www.repository.tabulation.XfgcSummaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class XfgcSummaryService extends BaseLogicService<XfgcSummary,Long> {
    @Autowired
    private XfgcSummaryRepository repository;
    @Override
    public XfgcSummaryRepository getRepository() {
        return repository;
    }


    /**
     * 标底：生成清单关联基础信息
     * @param project
     * @param jieDuan
     */
    public void saveCorrelationBd(Project project, Integer jieDuan,String fileName){
        XfgcSummary innerSummarie = null;
        if (jieDuan == 1){
            innerSummarie = getRepository().getByConditionJieDuanOne(project.getId());
        }
        if (innerSummarie == null){
            innerSummarie = new XfgcSummary();
            innerSummarie.setProject(project);
            innerSummarie.setJieDuan(jieDuan);
            innerSummarie.setFileName(fileName);
        }
        repository.save(innerSummarie);
    }


    /**
     * 供应商清单：生成清单关联基础信息
     * @param biddingCompany
     * @param jieDuan
     * @param fileName
     */
    public void saveCorrelationGys(XfgcBiddingCompany biddingCompany, Integer jieDuan, String fileName){
        XfgcSummary innerSummarie = null;
        if (jieDuan != 1){
            innerSummarie = repository.getByConditionJieDuanTemp(biddingCompany.getProject().getId(),biddingCompany.getId(),jieDuan);
        }
        if (innerSummarie == null){
            innerSummarie = new XfgcSummary();
            innerSummarie.setProject(biddingCompany.getProject());
            innerSummarie.setXfgcBiddingCompany(biddingCompany);
            innerSummarie.setJieDuan(jieDuan);
            innerSummarie.setFileName(fileName);
        }
        repository.save(innerSummarie);
    }

}
